Skip to content

Comments

Track session context changes during task execution#19

Merged
colindembovsky merged 6 commits intomainfrom
copilot/enhance-session-context-tracking
Feb 18, 2026
Merged

Track session context changes during task execution#19
colindembovsky merged 6 commits intomainfrom
copilot/enhance-session-context-tracking

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

Copilot SDK v0.1.24+ exposes session.context_changed events and SessionContext in session metadata. This enables tracking when agents change working directories during task execution.

Changes

SDK Integration

  • Updated @github/copilot-sdk to ^0.1.24 for context tracking support
  • Added optional onSessionEvent callback to StreamCallbacks in copilot.ts
  • Modified sendPrompt to listen for all session events when callback provided

Executor Layer

  • Created SessionEventWithTask type to associate session events with task IDs
  • Extended ExecutionCallbacks with optional onSessionEvent callback
  • Modified executeTask and init task to forward session events with task context

UI Display

  • Track current working directory per task from session.start and session.context_changed events
  • Display working directory under each task in task list: 📁 /workspace/path (repo@branch)
  • Show recent context changes for selected task with timestamps
  • Bounded to 100 events to prevent memory growth

Testing

  • Added unit tests for SessionEventWithTask type and callback handling

Example

When an agent changes directories during execution:

onSessionEvent: (eventWithTask) => {
  if (eventWithTask.event.type === 'session.context_changed') {
    const { cwd, repository, branch } = eventWithTask.event.data;
    setTaskContexts((prev) => ({
      ...prev,
      [eventWithTask.taskId]: { cwd, repository, branch },
    }));
  }
}

UI renders:

◉ task-1 — Create authentication module
📁 /workspace/backend/auth (owner/repo@main)

Context Changes:
14:23:45 → /workspace/backend (owner/repo@main)
14:24:12 → /workspace/backend/auth (owner/repo@main)
Original prompt

This section details on the original issue you should resolve

<issue_title>[enhancement] Track session context changes during task execution</issue_title>
<issue_description>## Background

The Copilot SDK recently added session context tracking capabilities in PR colindembovsky/planeteer#427 (included in v0.1.24, Feb 16, 2026). This enhancement, authored by Jeremy Moseley, introduces:

  1. SessionContext exposed in SessionMetadata - provides working directory, git root, repository, and branch information
  2. session.context_changed event - fires when working directory context changes between turns
  3. listSessions() filtering - ability to filter sessions by context fields (cwd, gitRoot, repository, branch)

Related SDK commits:

Proposal

Enhance Planeteer's execution screen to track and display when Copilot agent sessions change working directories during task execution. This would:

  1. Listen for session.context_changed events from each Copilot agent session during parallel task execution
  2. Display context changes in the event log alongside other session events (tool calls, outputs, etc.)
  3. Show current working directory for each running task in the execution UI
  4. Help users understand what directories agents are operating in, especially for tasks that span multiple repositories or workspaces

Benefit

This enhancement improves transparency and debugging during execution by:

  • Visibility: Users can see when an agent changes directories or switches git repositories during task execution
  • Debugging: When tasks fail, knowing the working directory context helps diagnose issues (e.g., running commands in wrong directory)
  • Multi-workspace support: For projects spanning multiple repos, users can verify agents are working in the correct context
  • Audit trail: The execution log becomes a complete record of not just what was done, but where it was done

Acceptance Criteria

  • Subscribe to session.context_changed events in src/services/executor.ts for each agent session
  • Display context change events in the execution screen event log with timestamp, task ID, and new context (cwd, repository, branch)
  • Show current working directory for each running task in the execution UI (e.g., next to task status)
  • Update the SessionEventWithTask type to include context change events
  • Add unit tests verifying context change events are captured and associated with the correct task
  • Update SDK dependency to ^0.1.24 or later in package.json if needed

AI generated by Weekly Enhancement Suggestions

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 18, 2026 08:17
- Updated SDK to ^0.1.24 (installed 0.1.25)
- Added SessionEvent import and re-export in copilot.ts
- Extended StreamCallbacks with onSessionEvent callback
- Modified sendPrompt to listen for all session events
- Updated sendPromptSync to accept and pass session event callback
- Added SessionEventWithTask type in executor.ts
- Extended ExecutionCallbacks with onSessionEvent callback
- Updated executeTask and init task to forward session events
- Added session event tracking in execute.tsx
- Display current working directory for running tasks
- Show context change events in task details

Co-authored-by: colindembovsky <1932561+colindembovsky@users.noreply.github.com>
- Created executor.test.ts with tests for SessionEventWithTask type
- Verified context change events are correctly structured
- Tested session.start events with context
- Verified ExecutionCallbacks accepts optional onSessionEvent
- All tests passing

Co-authored-by: colindembovsky <1932561+colindembovsky@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance session context tracking during task execution Track session context changes during task execution Feb 18, 2026
Copilot AI requested a review from colindembovsky February 18, 2026 08:21
@colindembovsky colindembovsky marked this pull request as ready for review February 18, 2026 16:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Copilot SDK session context tracking into Planeteer’s execution flow so the UI can show per-task working directory (and related repo metadata) and recent context-change history during execution.

Changes:

  • Bumped @github/copilot-sdk to ^0.1.24 and re-exported SessionEvent from copilot.ts.
  • Threaded optional onSessionEvent through copilot.tsexecutor.tsexecute.tsx.
  • Added basic unit tests around the new types/callback shape.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/services/copilot.ts Re-exports SessionEvent and optionally forwards session events from SDK sessions.
src/services/executor.ts Introduces SessionEventWithTask and forwards session events with task IDs through ExecutionCallbacks.
src/screens/execute.tsx Captures session events and renders cwd + recent context changes in the task UI.
src/services/executor.test.ts Adds tests for the new type and callback optionality.
package.json Updates Copilot SDK dependency range to enable context tracking support.
package-lock.json Locks updated SDK (and transitive) versions.

const [summarized, setSummarized] = useState('');
const [sessionEvents, setSessionEvents] = useState<SessionEventWithTask[]>([]);
const [taskContexts, setTaskContexts] = useState<Record<string, { cwd?: string; repository?: string; branch?: string }>>({});

Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sessionEvents and taskContexts are kept across retries / reruns (runCount changes) and are not cleared when restarting execution. This can show stale cwd/repo/branch from a previous run or from before a task retry. Consider resetting these states when a new run starts, and clearing per-task context when retrying that task.

Suggested change
useEffect(() => {
// When a new execution run starts, clear any session events and per-task
// contexts from previous runs to avoid showing stale cwd/repo/branch data.
if (runCount === 0) {
return;
}
setSessionEvents([]);
setTaskContexts({});
}, [runCount]);

Copilot uses AI. Check for mistakes.
Comment on lines +360 to +365
{context?.cwd && (
<Box marginLeft={4}>
<Text color="cyan" dimColor>📁 {context.cwd}</Text>
{context.repository && (
<Text color="blue" dimColor> ({context.repository})</Text>
)}
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task list context display omits branch even though it’s captured in taskContexts and the PR description example shows repo@branch. Consider including branch here (when present) to match the intended UI output.

Copilot uses AI. Check for mistakes.
Comment on lines 114 to 125
try {
const prompt = buildTaskPrompt(task, updatedPlan, codebaseContext);
const result = await sendPromptSync(EXECUTOR_SYSTEM_PROMPT, [
{ role: 'user', content: prompt },
], {
onDelta: (delta, fullText) => {
callbacks.onTaskDelta(task.id, delta, fullText);
},
onSessionEvent: (event) => {
callbacks.onSessionEvent?.({ taskId: task.id, event });
},
});
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New behavior forwards onSessionEvent from sendPromptSync into ExecutionCallbacks with task context. The added tests currently only construct objects / check optionality and don’t verify that executePlan actually invokes callbacks.onSessionEvent during execution (including the init task). Please add a unit test that mocks sendPromptSync to emit a SessionEvent and asserts the callback receives { taskId, event }.

Copilot uses AI. Check for mistakes.
colindembovsky and others added 3 commits February 18, 2026 10:54
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@colindembovsky colindembovsky merged commit 0249d75 into main Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[enhancement] Track session context changes during task execution

2 participants